//***********************************************************************
//	File:		Entity.cpp
//	Author:		Spencer Hawkins
//	Course:		SGP 1405
//	Purpose:	To load up base information about each entity 
//***********************************************************************
//***********************************************************************
//	Purposfully left blank for all comments regarding this file 
//	
//	
//	
//***********************************************************************

#pragma once

#include "Entity.h"
#include "../SGD Wrappers/SGD_GraphicsManager.h"
#include "../TileSystem/TileSystem.h"

void Entity::Update ( float dt )
{
	SGD::Rectangle newP = GetRect ();
	newP.left += m_vVelocity.x*dt;
	newP.right += m_vVelocity.x*dt;
	newP.top += m_vVelocity.y*dt;
	newP.bottom += m_vVelocity.y*dt;
	if ( TILESYSTEM->CheckWorld ( newP ) == SGD::Rectangle {0.0f, 0.0f, 0.0f, 0.0f} )
		m_ptPosition += m_vVelocity * dt;
}

void Entity::Render ( void )
{


	if ( m_hImage != SGD::INVALID_HANDLE )
		SGD::GraphicsManager::GetInstance ()->DrawTexture (
		m_hImage , m_ptPosition , m_fRotation );

}

SGD::Rectangle	Entity::GetRect ( void )	const
{
	return SGD::Rectangle { m_ptPosition.x - (m_szSize.width / 2) ,
		m_ptPosition.y - (m_szSize.height / 2) ,
		m_ptPosition.x + (m_szSize.width / 2) ,
		m_ptPosition.y + (m_szSize.height / 2) , };
}

void Entity::HandleCollision ( const IEntity* pOther )
{
	(void)pOther; // so it doesnt get mad at me
}

void Entity::AddRef ( void )
{
	m_unRefCount++;
}

void Entity::Release ( void )
{
	m_unRefCount--;
	if ( m_unRefCount == 0 )
	{
		delete this;
	}
}


